	package dangs.controller;
	
	import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import dangs.dao.LocationDAO;
import dangs.dao.MemberDAO;
import dangs.vo.LocationVO;
import dangs.vo.MemberVO;
	
	public class RegisterMemberController extends MultiActionController{
	 private MemberDAO dao;
	 private LocationDAO lDao;
	 
	 public void setMemberDAO(MemberDAO dao){
		 this.dao = dao;
	 }
	 public void setLocationDAO(LocationDAO lDao){
		 this.lDao = lDao;
	 }
	 
	 public ModelAndView registerForm(HttpServletRequest request, HttpServletResponse response) throws Exception{
		 ArrayList list = lDao.selectAllLocation();
		 request.setAttribute("list", list);
		 return new ModelAndView("register_member");
	 }
	 public ModelAndView insertMember(HttpServletRequest request, HttpServletResponse response, MemberVO mvo) throws Exception{
			String locationCode = request.getParameter("locationCode");
			LocationVO lvo = new LocationVO();
			lvo.setLocationCode(locationCode);
			mvo.setLvo(lvo);
			dao.insertMember(mvo);
			mvo = dao.selectMemberById(mvo.getMemberId());
			return new ModelAndView("register_success", "mvo", mvo);
	 }
	 public ModelAndView updateForm(HttpServletRequest request, HttpServletResponse response) throws Exception{
		HttpSession session = request.getSession();
		String memberId = (String)session.getAttribute("id");
		MemberVO mvo = dao.selectMemberById(memberId);
		ArrayList list = lDao.selectAllLocation();
		request.setAttribute("list", list);
		return new ModelAndView("modify_member","mvo", mvo); 
	 }
	 public ModelAndView updateMember(HttpServletRequest request, HttpServletResponse response, MemberVO mvo) throws Exception{
		HttpSession session = request.getSession();
		String memberId = (String)session.getAttribute("id");
		mvo.setMemberId(memberId);
		 String locationCode = request.getParameter("locationCode");
		 LocationVO lvo = new LocationVO();
		 lvo.setLocationCode(locationCode);
		 mvo.setLvo(lvo);
		 int cnt = dao.updateMember(mvo);
		 System.out.println(cnt);
		 mvo = dao.selectMemberById(memberId);
		 return new ModelAndView("modify_success", "mvo", mvo);
	 }
	 public ModelAndView deleteMember(HttpServletRequest request, HttpServletResponse response, MemberVO mvo) throws Exception{
			HttpSession session = request.getSession();
			String memberId = (String)session.getAttribute("id");
			dao.deleteMember(memberId);
			 return new ModelAndView("delete_member_success", "mvo", mvo);
	 	}
	  
} 